package com.zlsy.learning.leetcode.queue;

/**
 * @author zhouliang
 * @date 2020/8/13 16:12
 */
public class CircularQueue {

  private String[] items;
  private int size = 0;
  private int tail = 0;
  private int head = 0;

  private CircularQueue() {}

  public CircularQueue(int capital) {
    items = new String[capital];
    size = capital;
  }

  public boolean equeue(String item) {
    boolean isFull = (tail + 1) % size == head;
    if (isFull) {
      return false;
    }
    // 入队
    items[tail] = item;
    tail = (tail + 1) % size;
    return false;
  }

  public String dqueue() {
    if (head == tail) {
      return null;
    }
    String ret = items[head];
    head = (head + 1) % size;
    return ret;
  }
}
